package com.chench.interview.spring;

import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Scope(value = "singleton")
@RestController
public class ThreadSafeTest {
    private ThreadLocal<Integer> inital = ThreadLocal.withInitial(() ->{
        return 0;
    });

    @GetMapping(value = "/api/getNumber1")
    public int number1(){
        inital.set(1);
        System.out.println("inital = " + inital.get());
        return inital.get();
    }
    @GetMapping(value = "/api/getNumber2")
    public int number2(){
        System.out.println("inital = " + inital.get());
        return inital.get();
    }
}
